package com.dyava.dycache.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CacheEngineContext {
    List<CacheEngine> cacheEngineList = new ArrayList<>();
    Map<String,CacheDefined> cacheDefinedMap = new HashMap<>();

    public void addCacheDefined(CacheDefined cacheDefined){
        cacheDefinedMap.put(cacheDefined.getName(),cacheDefined);
    }

    public void addCacheEngine(CacheEngine cacheEngine){
        cacheEngineList.add(cacheEngine);
    }


    public CacheEngine firstCacheEngine(){
        return cacheEngineList.get(0);
    }

    public CacheEngine nextCacheEngine(CacheEngine cacheEngine){
        int index = cacheEngineList.indexOf(cacheEngine);
        if(index+1 < cacheEngineList.size()){
            return cacheEngineList.get(index+1);
        }else{
            return null;
        }
    }

    public CacheEngine lastCacheEngine(){
        if(cacheEngineList.size()>2){
            return cacheEngineList.get(cacheEngineList.size()-1);
        }else{
            return null;
        }
    }

    public int indexOf(CacheEngine cacheEngine){
        int index = cacheEngineList.indexOf(cacheEngine);
        return index;
    }



}
